package com.boboPlanet.user.mq.peoducerBean;

import com.boboPlanet.user.mq.PlanetMiddleMqEnum;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: TODO 用户登录rabbitmq配置
 * @Author: mis_wu
 * @Date: 2023/3/23
 **/
@Configuration
public class UserMiddleRabbitMqConfig {

    @Bean
    public Queue userMiddleQueue(){
        return QueueBuilder.durable(PlanetMiddleMqEnum.USER_LOGIN_MQ.getQueue()).build();
        //return new Queue(PlanetMiddleMqEnum.USER_LOGIN_MQ.getQueue(),true);
    }

    @Bean
    TopicExchange userMiddleExchange() {
        return new TopicExchange(PlanetMiddleMqEnum.USER_LOGIN_MQ.getExchange(),true,false);
    }

    /**
     * todo:路由绑定交换机(routing-key)
     * @return Binding
     */
    @Bean
    Binding userMiddleRoutingKey() {
        return BindingBuilder.bind(this.userMiddleQueue())
                .to(this.userMiddleExchange())
                .with(PlanetMiddleMqEnum.USER_LOGIN_MQ.getRoutingKey());
    }

}
